package org.buptsse.thread;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.util.ArrayList;

import org.buptsse.utils.APPConstant;
import org.buptsse.utils.ConnectionChecker;
import org.buptsse.utils.HttpHelper;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

public class DeleteSellPhotoThread extends Thread {

	private Context context;
	private Handler handler;
	private String sellid,deleteuri;
	
	public DeleteSellPhotoThread(Context context,Handler handler,String sellid,String deleteuri)
	{
		this.context=context;
		this.handler=handler;
		this.sellid=sellid;
		this.deleteuri=deleteuri;
	}
	public void run()
	{
		if(ConnectionChecker.CheckConnection(context, handler)==false)
			return;
		ArrayList<NameValuePair> param=new ArrayList<NameValuePair>();
		param.add(new BasicNameValuePair("sellid", sellid));
		param.add(new BasicNameValuePair("deleteuri", deleteuri));
		try {
			String result=HttpHelper.sendPost(APPConstant.deleteSellPhotoUrl, param);
			System.out.println("delete sell photo result:"+result);
			if(result.contains("success"))
			{
				Message msg=handler.obtainMessage(APPConstant.deleteSellPhotoFinish);
				handler.sendMessage(msg);
			}else {
				Message msg=handler.obtainMessage(APPConstant.deleteSellPhotoError);
				handler.sendMessage(msg);
			}
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
